﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for OrderDAL
/// </summary>
public class OrderDAL
{
    DatabaseAccess dba = new DatabaseAccess();

	public OrderDAL()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public bool InsertOrder(Order objO)
    { 
       SqlParameter[] paramList = new SqlParameter[19];
       paramList[0] = new SqlParameter("@od_code",SqlDbType.VarChar,15);
       paramList[0].Value = objO.OdCode;
       paramList[1] = new SqlParameter("@cus_id",SqlDbType.Int);
       paramList[1].Value = objO.CusId;
       paramList[2] = new SqlParameter("@od_date",SqlDbType.DateTime);
       paramList[2].Value = objO.OrderDate;
       paramList[3] = new SqlParameter("@od_status", SqlDbType.NVarChar,50);
       paramList[3].Value = objO.Status;
       paramList[4] = new SqlParameter("@od_shipping_firstname",SqlDbType.NVarChar,50);
       paramList[4].Value = objO.ShipFname;
       paramList[5] = new SqlParameter("@od_shipping_lastname", SqlDbType.NVarChar, 50);
       paramList[5].Value = objO.ShipLname;
       paramList[6] = new SqlParameter("@od_shipping_email",SqlDbType.VarChar,30);
       paramList[6].Value = objO.ShipEmail;
       paramList[7] = new SqlParameter("@od_shipping_address",SqlDbType.NVarChar,250);
       paramList[7].Value = objO.ShipAddress;
       paramList[8] = new SqlParameter("@od_shipping_phone",SqlDbType.NVarChar,15);
       paramList[8].Value = objO.ShipPhone;
       paramList[9] = new SqlParameter("@od_shipping_state",SqlDbType.NVarChar,20);
       paramList[9].Value = objO.ShipState;
       paramList[10] = new SqlParameter("@od_shipping_city",SqlDbType.NVarChar,20);
       paramList[10].Value = objO.ShipCity;
       paramList[11] = new SqlParameter("@od_shipping_zipcode",SqlDbType.VarChar,10);
       paramList[11].Value = objO.ShipZipCode;
       paramList[12] = new SqlParameter("@od_payment_name",SqlDbType.NVarChar,50);
       paramList[12].Value = objO.PayName;
       paramList[13] = new SqlParameter("@od_payment_cardtype",SqlDbType.NVarChar,20);
       paramList[13].Value = objO.PayCardType;
       paramList[14] = new SqlParameter("@od_payment_cardnum",SqlDbType.NVarChar,15);
       paramList[14].Value = objO.PayCardNum;
       paramList[15] = new SqlParameter("@od_payment_expridate",SqlDbType.DateTime);
       paramList[15].Value = objO.PayExpri;
       paramList[16] = new SqlParameter("@od_payment_verinum",SqlDbType.VarChar,20);
       paramList[16].Value = objO.PayVeriNum;
       paramList[17] = new SqlParameter("@od_quantity",SqlDbType.Int);
       paramList[17].Value = objO.Quantity;
       paramList[18] = new SqlParameter("@od_totalprice", SqlDbType.Money);
       paramList[18].Value = objO.Totalmoney;
       return dba.executeUpdate("proc_insertOrder", paramList);
    }
    public bool InsertOrderItem(int OrderID,int ProductID,int quantity, decimal Money)
    {
        SqlParameter[] paramList = new SqlParameter[4];
        paramList[0] = new SqlParameter("@od_id",SqlDbType.Int);
        paramList[0].Value = OrderID;
        paramList[1] = new SqlParameter("@pd_id",SqlDbType.Int);
        paramList[1].Value = ProductID;
        paramList[2] = new SqlParameter("@odi_quantity",SqlDbType.Int);
        paramList[2].Value = quantity;
        paramList[3] = new SqlParameter("@odi_price",SqlDbType.Money);
        paramList[3].Value = Money;
        return dba.executeUpdate("proc_insertOrderItem",paramList);
    }

    public DataTable GetOdID(int cus_id, String od_code)
    {
        SqlParameter[] paramList = new SqlParameter[2];
        paramList[0] = new SqlParameter("@cus_id",SqlDbType.Int);
        paramList[0].Value = cus_id;
        paramList[1] = new SqlParameter("@od_code",SqlDbType.VarChar,15);
        paramList[1].Value = od_code;
        return dba.executeSelect("getOrderByCusIdAndCode", paramList);
    }

    public DataTable GetOrderByCode(String od_code)
    {
        SqlParameter[] paramList = new SqlParameter[1];
        paramList[0] = new SqlParameter("@od_code",SqlDbType.VarChar,15);
        paramList[0].Value = od_code;
        return dba.executeSelect("getOrderByCode", paramList);
    }

}